import java.util.Scanner;

public class Java5 {
    //类
    public static int sum(int a,int b) {
        return (a+b);
    }

    public static int sum(int a,int b,int c) {
        return (a+b+c);
    }

    public static double sum(int a,double b) {
        return (a+b);
    }

    public static double sum(double b,int a) {
        return (a+b);
    }
                                                //这三个方法构成了重载
    public static double sum(double a,double b) {
        return (a+b);
    }                                           //方法名称必须相同
                                                //方法的参数列表不同（顺序，个数，类型）
                                                //和返回值没有关系
    public static void main(String[] args) {
        //方法重载
        int a = 10;
        int b = 20;
        int ret = sum(a,b);
        System.out.println(ret);

        double d1 = 12.4;
        double d2 = 17.4;
        double ret2 = sum(d1,d2);
        System.out.println(ret2);

        System.out.println(sum(1, 2, 3));

    }

    public static void swap(int a,int b) {
        //形参的改变 并没有改变实参
        //学习类和对象之后 才能解决这个问题
        int tmp = a;
        a = b;
        b = tmp;
    }

    public static void main19(String[] args) {
        int a = 10;
        int b = 20;
        swap(a,b);//没有交换实参的值
        System.out.println(a);
        System.out.println(b);
    }

    public  static int facNum(int num) {
        //求数字阶层的和
        int sum = 0;
        for (int j = 1; j <= num; j++) {
            //int ret = fac(j);
            sum += fac(j);
            }
        //System.out.println(sum);
        return sum;
    }

    public static int fac(int n) {
        //求数字阶层
        int ret = 1;
        for (int i = 1; i <= n; i++) {
            ret *= i;
        }
        return ret;
    }

    public static void main18(String[] args) {
        /*int ret = facNum(5);
        System.out.println(ret);*/
        System.out.println(facNum(5));//.sout快捷键
    }

                            //形参
    public static int add(int a,int b) {//局部变量
        int c = 99;//局部变量
        return a+b;//方法结束 add方法开辟的栈 就被回收了
    }
    //1.方法的调用是在栈上的
    //2.当方法遇上return或者遇上右括号代表当前方法结束了，对应方法开辟的栈帧回收了

    public static void main17(String[] args) {
        //方法的执行是在一块内存当中的，这块内存叫做栈
        int a = 10;//实参
        int b = 20;
        //实参
        //无返回值不能接收
        int ret1 = add(1,2);//调用一个方法的语法 方法名（）
        //这个a:b:为编译器加上的
        System.out.println("使用返回值："+ret1);
        int p = ret1 * 5;
        System.out.println(p);

        int ret2 = add(a,b);//int ret接受返回值
        System.out.println("使用返回值："+ret2);
    }

                                    //形参属于局部变量
    public static boolean isLeapYear(int year) {
        //类型和个数都要匹配，顺序都要匹配
        //一一匹配的
        //int year = 1900;//重复定义
        if((0 == year % 4 && 0 != year % 100) || 0 == year % 400){
            //System.out.println(year+"年是闰年");
            return true;
        }else{
            //System.out.println(year+"年不是闰年");
            return false;
        }
    }

    //方法
    public static void main16(String[] args) {
        for (int i = 1000; i < 2000; i++) {
            boolean flg = isLeapYear(i);//接受返回值
            //类型不能改变
            if (flg == true) {
                System.out.println(i+"是闰年");//传参
            }
        }
    }

    //作业题目讲评
    public static void main15(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) {
                    System.out.print("*");
                }else if (i + j == n-1) {
                    System.out.print("*");
                }else System.out.print(" ");
            }
            System.out.println();
        }
    }

    public static void main14(String[] args) {
        //判断1-100有多少个数字包含9
        int count = 0;
        for (int i = 1; i <= 100; i++) {
            if (i % 10 == 9) {
                count++;
            }else if (i / 10 == 9) {
                count++;
            }
        }
        System.out.println(count);
    }

    public static void main13(String[] args) {
        //判断1-100有多少个9
        int count = 0;
        for (int i = 1; i <= 100; i++) {
            if (i % 10 == 9) {
                count++;
            }
            if (i / 10 == 9) {
                count++;
            }
        }
        System.out.println(count);
    }

    public static void main12(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        //偶数位
        for (int i = 31; i >= 1 ; i-=2) {
            System.out.println(((n >> 1) & 1)+" ");
        }
        System.out.println();
        for (int i = 30; i >= 0; i-=2) {
            System.out.println(((n >> 1) & 1)+" ");
        }
    }

    public static void main11(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int count = 0;

        while (n != 0) {
            n = n & (n-1);
            count++;
        }
        System.out.println(count);
    }

    public static void main10(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int count = 0;

        while (n != 0) {
            if ((n & 1) != 0) {
                count++;
            }
            n = n >>> 1;
        }
        System.out.println(count);
    }

    public static void main9(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int count = 0;
        for (int i = 0; i < 32; i++) {
            if( ((n >>> i) & 1) != 0) {
                count++;
            }
        }
        System.out.println(count);
    }

    public static void main8(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int a = 0;
        int b = 0;
        int x = 0;
        for (int i = 0; i <= n; i++) {
            //判断i是几位数 求每位上是几 加起来为原来数字
            int count = 0;
            int tmp = i;
            while (tmp != 0) {
                count++;
                tmp = tmp / 10;
            }
            //tmp为0 i还是原来的值
            tmp = i;
            int sum = 0;
            while (tmp != 0) {
                sum += Math.pow(tmp % 10,count);
                tmp /= 10;
            }
            if (sum == i) {
                System.out.println(i);
            }
        }
    }

    public static void main7(String[] args) {
        //水仙花数
        int a = 0;
        int b = 0;
        int c = 0;
        for (int i = 100; i < 999; i++) {
            a = i / 100;
            b = i / 10 % 10;
            c = i % 10;
            if ((a*a*a) + (b*b*b) + (c*c*c)==i) {
                System.out.println(i);
            }
        }
    }

    public static void main6(String[] args) {
        //求最大公约数 辗转相除法
        Scanner  scanner = new Scanner(System.in);
        System.out.println("请输入第一个整数");
        int n = scanner.nextInt();
        System.out.println("请输入第二个整数");
        int m = scanner.nextInt();
        int c = 0;
        while (n % m != 0) {
            c = n % m;
            n = m;
            m = c;
        }
        System.out.println(m);
    }

    public static void main5(String[] args) {
        Scanner  scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(i+"*"+j+"="+i*j+" ");
            }
            System.out.println();
        }
    }

    public static void main4(String[] args) {
        Scanner  scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int j = 1; j <= n; j++) {
            int i = 2;
            for (; i <= Math.sqrt(j); i++) {
                if (j % i == 0) {
                    break;
                }
            }
            if (i > Math.sqrt(j)) {
                System.out.println(j+"是素数");
            }
        }
    }

    public static void main3(String[] args) {
        Scanner  scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int i = 2;
        //开根号
        for (; i <= Math.sqrt(n); i++) {
            if (n % i == 0) {
                System.out.println(n+"不是素数");
                break;
            }
        }
        if (i > Math.sqrt(n)) {
            System.out.println(n+"是素数");
        }
    }

    public static void main2(String[] args) {
        Scanner  scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int i = 2;
        for (; i <= n/2; i++) {
            if (n % i == 0) {
                System.out.println(n+"不是素数");
                break;
            }
        }
        if (i > n/2) {
            System.out.println(n+"是素数");
        }
}

    public static void main1(String[] args) {
        Scanner  scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int i = 2;
        for (; i < n; i++) {
            if (n % i == 0) {
                System.out.println(n+"不是素数");
                break;
            }
        }
        if (n == i) {
            System.out.println(n+"是素数");
        }
    }
}
